import createPersistedState from 'vuex-persistedstate'

/**
 * vuex持久化
 */
export default ({ store, isHMR }) => {
  if (isHMR) return

  window.onNuxtReady(() => {
    createPersistedState({
      key: 'adminx',
      Storage: localStorage,
      // An array of any paths to partially persist the state.
      // Paths are using dots to indicate nestedness.
      paths: ['i18n.locale']
    })(store)
  })
  // Just in case nuxt.config.js gets a change in ssr:false when adding this plugin.
  // Notice isClient is deprecated, instead use process.browser.
  // In case of HMR, mutation occurs before nuxtReady, so previously saved state
  // gets replaced with original state received from server. So, we've to skip HMR.
  // Also nuxtReady event fires for HMR as well, which results multiple registration of
  // vuex-persistedstate plugin
  // if (process.browser) {
  //   if (isHMR) return
  //   createPersistedState({
  //     key: 'adminstore'
  //   })(store)
  // }
}
